
#ifndef _MEMBER_BSTYLE_H_
#define _MEMBER_BSTYLE_H_

#include <BMap>
#include <BFont>
#include <BIcon>
#include <BImage>
#include <BStyle>

#define style_member(style)		((member_BStyle*)((BStyle*)style)->_ptr)

namespace BWE
{
	class BLayout;
	class BWidget;
	class IAlignItem;
	class BGraphicItem;

	class member_BStyle
	{
	public:
		member_BStyle(BStyle* style);
		~member_BStyle();

		void init(const BColor& color);
		BStyle* initItemStyle(const BColor& color);
		BStyle* initHeaderStyle(const BColor& color);

		bool apply(BWidget* widget, bool ischild) const;
		bool apply(BLayout* layout, bool primary) const;
		bool apply(IAlignItem* item) const;
		bool apply(BGraphicItem* item) const;
		void overlap(const BStyle* style);

		bool setMetaValue(const BString& name, BString& value);
		bool setBoolValue(StyleValue name, const BString& value);
		bool setIntValue(StyleValue name, const BString& value);
		bool setWordValue(StyleValue name, const BString& value);
		bool setFloatValue(StyleValue name, const BString& value);
		bool setPointValue(StyleValue name, const BString& value);
		bool setSizeValue(StyleValue name, const BString& value);

		bool setAlignValue(StyleValue name, const BString& value);
		bool setPartValue(StyleValue name, const BString& value);
		bool setFormValue(StyleValue name, const BString& value);
		bool setGraphValue(StyleValue name, const BString& value);
		bool setPolicyValue(StyleValue name, const BString& value);
		bool setOrientation(StyleValue name, const BString& value);
		bool setScrollStep(StyleValue name, const BString& value);
		bool setScrollHint(StyleValue name, const BString& value);
		bool setGridStyle(StyleValue name, const BString& value);

		void raiseSignal(int signal, const BValue& value = BValue());

		template<class T>
		bool assign(int name, T& value)
		{
			auto it = valueMap.find(name);
			if (it.empty())
				return false;
			if (!it->is<T>())
				return false;
			value = (const T&)*it;
			return true;
		}

		template<class T>
		bool assign(int name, BHolder<T>& holder)
		{
			auto it = valueMap.find(name);
			if (it.empty())
				return false;
			if (!it->is<T>())
				return false;
			holder = (T*)*it;
			return true;
		}

		BStyle*				boss;
		BStyle*				parent;
		BString				type;
		BString				unset;
		bool				heritable;
		bool				descendant;

		BMap<StyleValue, BValue>	valueMap;
		BMap<int, BColor>			colorMap;
		BMap<int, BImageHolder>		imageMap;
		BMap<int, BIconHolder>		iconMap;
		BMap<BString, BValue>		namedValueMap;
		BMap<BString, BColor>		namedColorMap;
		BMap<BString, BImageHolder>	namedImageMap;
		BMap<BString, BIconHolder>	namedIconMap;
		BMap<BString, BString>		transMap;
		BMap<BString, BString>		wordMap;
		BMap<BString, BString>		textMap;
		BArray<BStyleHolder>		annexes;
		BArray<BStyleHolder>		children;
	};
}

#endif
